<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="订单所属ID，取值ORDER的ID(数字0：未插入)" prop="orderId">
        <el-input v-model="dataForm.orderId" placeholder="订单所属ID，取值ORDER的ID(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否关注该收藏商品(数字0：未插入，1.关注收藏,2：取消收藏，)" prop="isAttention">
        <el-input v-model="dataForm.isAttention" placeholder="是否关注该收藏商品(数字0：未插入，1.关注收藏,2：取消收藏，)"></el-input>
      </el-form-item>
      <el-form-item label="支付状态(数字0：未插入，1待付款;   2已付款)" prop="payStatus">
        <el-input v-model="dataForm.payStatus" placeholder="支付状态(数字0：未插入，1待付款;   2已付款)"></el-input>
      </el-form-item>
      <el-form-item label="发货状态(数字0：未插入，1待发货; 2已发货  3取消发货  4备货中)" prop="shippingStatus">
        <el-input v-model="dataForm.shippingStatus" placeholder="发货状态(数字0：未插入，1待发货; 2已发货  3取消发货  4备货中)"></el-input>
      </el-form-item>
      <el-form-item label="收货状态(数字0：未插入，1待收货; 2已收货  3退货  4备货中)" prop="receivedStatus">
        <el-input v-model="dataForm.receivedStatus" placeholder="收货状态(数字0：未插入，1待收货; 2已收货  3退货  4备货中)"></el-input>
      </el-form-item>
      <el-form-item label="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)" prop="orderStatus">
        <el-input v-model="dataForm.orderStatus" placeholder="订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)"></el-input>
      </el-form-item>
      <el-form-item label="操作员(字符串空：未插入)" prop="operator">
        <el-input v-model="dataForm.operator" placeholder="操作员(字符串空：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="创建即上传时间(数字0：未插入)" prop="createUtc">
        <el-input v-model="dataForm.createUtc" placeholder="创建即上传时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="修改即更新时间(数字0：未插入)" prop="modifyUtc">
        <el-input v-model="dataForm.modifyUtc" placeholder="修改即更新时间(数字0：未插入)"></el-input>
      </el-form-item>
      <el-form-item label="是否删除(数字0：未插入，1.未删除,2：删除，)" prop="isDeleted">
        <el-input v-model="dataForm.isDeleted" placeholder="是否删除(数字0：未插入，1.未删除,2：删除，)"></el-input>
      </el-form-item>
      <el-form-item label="版本号(数字0：未插入)" prop="version">
        <el-input v-model="dataForm.version" placeholder="版本号(数字0：未插入)"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import API from '@/api'
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          orderId: '',
          isAttention: '',
          payStatus: '',
          shippingStatus: '',
          receivedStatus: '',
          orderStatus: '',
          operator: '',
          createUtc: '',
          modifyUtc: '',
          isDeleted: '',
          version: ''
        },
        dataRule: {
          orderId: [
            { required: true, message: '订单所属ID，取值ORDER的ID(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isAttention: [
            { required: true, message: '是否关注该收藏商品(数字0：未插入，1.关注收藏,2：取消收藏，)不能为空', trigger: 'blur' }
          ],
          payStatus: [
            { required: true, message: '支付状态(数字0：未插入，1待付款;   2已付款)不能为空', trigger: 'blur' }
          ],
          shippingStatus: [
            { required: true, message: '发货状态(数字0：未插入，1待发货; 2已发货  3取消发货  4备货中)不能为空', trigger: 'blur' }
          ],
          receivedStatus: [
            { required: true, message: '收货状态(数字0：未插入，1待收货; 2已收货  3退货  4备货中)不能为空', trigger: 'blur' }
          ],
          orderStatus: [
            { required: true, message: '订单状态(数字0：未插入，1已确认; 2已取消; 3无效; 4退货)不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '操作员(字符串空：未插入)不能为空', trigger: 'blur' }
          ],
          createUtc: [
            { required: true, message: '创建即上传时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          modifyUtc: [
            { required: true, message: '修改即更新时间(数字0：未插入)不能为空', trigger: 'blur' }
          ],
          isDeleted: [
            { required: true, message: '是否删除(数字0：未插入，1.未删除,2：删除，)不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号(数字0：未插入)不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            API.upkorderaction.info(this.dataForm.id).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.orderId = data.upkorderaction.orderId
                this.dataForm.isAttention = data.upkorderaction.isAttention
                this.dataForm.payStatus = data.upkorderaction.payStatus
                this.dataForm.shippingStatus = data.upkorderaction.shippingStatus
                this.dataForm.receivedStatus = data.upkorderaction.receivedStatus
                this.dataForm.orderStatus = data.upkorderaction.orderStatus
                this.dataForm.operator = data.upkorderaction.operator
                this.dataForm.createUtc = data.upkorderaction.createUtc
                this.dataForm.modifyUtc = data.upkorderaction.modifyUtc
                this.dataForm.isDeleted = data.upkorderaction.isDeleted
                this.dataForm.version = data.upkorderaction.version
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            var params = {
              'id': this.dataForm.id || undefined,
              'orderId': this.dataForm.orderId,
              'isAttention': this.dataForm.isAttention,
              'payStatus': this.dataForm.payStatus,
              'shippingStatus': this.dataForm.shippingStatus,
              'receivedStatus': this.dataForm.receivedStatus,
              'orderStatus': this.dataForm.orderStatus,
              'operator': this.dataForm.operator,
              'createUtc': this.dataForm.createUtc,
              'modifyUtc': this.dataForm.modifyUtc,
              'isDeleted': this.dataForm.isDeleted,
              'version': this.dataForm.version
            }
            var tick = !this.dataForm.id ? API.upkorderaction.add(params) : API.upkorderaction.update(params)
            tick.then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
